/*
 * Copyright 2006 Mark Bakker <bakker.mark AT gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.google.gwt.vector.client.impl;

import java.util.Iterator;
import java.util.Set;

import com.google.gwt.user.client.Element;
import com.google.gwt.vector.client.VML;
import com.google.gwt.vector.client.ui.Polyline.Point;

/**
 * The standard SVG implementation.
 */
public class VectorImplIE6 extends VectorImpl {

  public Element createCircle() {
    return createEclipse();
  }

  public Element createEclipse() {
    return VML.createEclipse();
  }

  public Element createFill() {
    return VML.createFill();
  }

  public Element createLine() {
	return VML.createLine();
  }

  public Element createPolyline() {
    return VML.createPolyline();
  }

  public Element createRectangle() {
    return VML.createRectangle();
  }

  public Element createStroke() {
    return VML.createStroke();
  }

  public Element createVectorGroup() {
    return VML.createVectorGroup();
  }

  public boolean isVml() {
    return true;
  }

  public void setAttribute(Element element, String key, String value) {
    VML.setAttributeNS(element, key, value);
  }

  public void setCoord(Element element, double coordinateX, double coordinateY, double width, double height) {
    VML.setCoordX(element, coordinateX);
    VML.setCoordY(element, coordinateY);
  }

  public void setDimension(Element element, double width, double height) {
    VML.setWidth(element, width);
    VML.setHeight(element, height);
  }

  public void setEclipseCoord(Element element, double coordinateX, double coordinateY, double radiusX, double radiusY) {
    VML.setCoordX(element, coordinateX - radiusX);
    VML.setCoordY(element, coordinateY - radiusY);
  }

  public void setFrom(Element element, double fromX, double fromY) {
    VML.setAttributeNS(element, "from", String.valueOf(fromX) + " " + String.valueOf(fromY));
  }

  public void setGroupDimension(Element element, double width, double height) {
    VML.setAttributeNS(element, "coordsize", width + ", " + height);
  }

  public void setPoints(Element element, Set points) {
	String pointString = "";
	for (Iterator iter = points.iterator(); iter.hasNext();) {
		Point point = (Point) iter.next();
		pointString = pointString + point.getX() + " " + point.getY();
		if (iter.hasNext()) {
			pointString = pointString + " ";
		}
	}
    VML.setAttributeNS(element, "points", pointString);
  }

  public void setRadius(Element element, double radius) {
    setRadius(element, radius, radius);
  }

  public void setRadius(Element element, double radiusX, double radiusY) {
    setDimension(element, radiusX + radiusX, radiusY + radiusY);
  }

  public void setTo(Element element, double toX, double toY) {
    VML.setAttributeNS(element, "to", String.valueOf(toX) + " " + String.valueOf(toY));
  }

}
